import { createSlice } from '@reduxjs/toolkit'

export const ticketSlice = createSlice({
  name: 'ticket',
  initialState: {
    start:'北京',
    end:'上海',
    searchHistory:[]
  },
  reducers: {
    setCity(state,actions){
        state[actions.payload.propName]=actions.payload.city
    },
    clearHistory(state){
        state.searchHistory=[]
    },
    addHistory(state,actions){
        state.searchHistory=actions.payload
        const set=new Set(state.searchHistory)
        state.searchHistory=Array.from(set)
    }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { setCity,clearHistory,addHistory} = ticketSlice.actions

export default ticketSlice.reducer